$(document).ready(function(){
    $(".imgInput").change(function(){
        var id = $(this).attr('id');
        console.log(id);
        
        data = (id === 'frontimg') ? new FormData($("#form-front")[0]) :  new FormData($("#form-back")[0]);
        $.ajax({
            url: "/user/default/authimgupload",
            type: "post",
            dataType: "json",
            cache: false,
            data: data,
            processData: false,// 不处理数据
            contentType: false, // 不设置内容类型
            success: function(data){
                console.log(data);
                if(id === 'frontimg'){
                    $("#frontimg-result").attr("src",data.url);
                    $("#frontimg-result").show();
                }
                if(id === 'backimg'){
                    $("#backimg-result").attr("src",data.url);
                    $("#backimg-result").show();
                }
            }

        })
    });
    
    $('#user-auth-submit').on('click',function(){
		
        var name = $("#name").val();
        if(name === ""){
			layer.msg('请输入姓名');
            return false;
        }
        
        var number = $("#number").val();
        if(number === ""){
			layer.msg('请输入身份证号码');
            return false;
        }
        
        var frontimg = $("#frontimg-result").attr("src");
        if(frontimg === ""){
			layer.msg('请上传身份证正面照片');			
            return false;
        }
        var backimg = $("#backimg-result").attr("src");
        if(backimg === ""){
			layer.msg('请上传身份证背面照片');
            return false;
        }
        
		var ii = layer.load(0, {shade: false});
		
        $params = JSON.stringify({'name':name,'number':number,'frontimg':frontimg,'backimg':backimg});
        $comment_back = ajaxSynchroRequest("/user/default/authsave",$params);
        console.log($comment_back);
        if($comment_back.success == 1){
			setTimeout(function(){
			    layer.close(ii);
				window.location.href = "/user/default/index";
			}, 2000);
            
        }
		
    });
});
